import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { JVxeTypes, JVxeColumn } from '/@/components/jeecg/JVxeTable/types'

var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
const newMonth = month < 9 ? `0${month}` : month
const newDay = day < 9 ? `0${day}` : day
const newDate = `${year}-${newMonth}-${newDay}`
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '母件编号',
    align: "center",
    sorter: true,
    dataIndex: 'materialCode',
    width: 180
  },
  {
    title: '母件名称',
    align: "center",
    sorter: true,
    dataIndex: 'materialName',
    width: 180
  },
   {
    title: '单位ID',
    align:"center",
    dataIndex: 'unitId',
    ifShow:false,
    width: 180
   },
  {
    title: '单位',
    align: "center",
    sorter: true,
    dataIndex: 'unitName',
    width: 100
  },
  {
    title: '版本',
    align: "center",
    dataIndex: 'bomVersion',
    width: 100
  },
  {
    title: '生效日期',
    align: "center",
    sorter: true,
    dataIndex: 'effectiveDate',
    customRender: ({ text }) => {
      return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
    },
    width: 100
  },
  {
    title: '失效日期',
    align: "center",
    sorter: true,
    dataIndex: 'expirationDate',
    customRender: ({ text }) => {
      return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
    },
    width: 100
  },
  {
    title: 'BOM生产目的',
    align: "center",
    dataIndex: 'productionPurpose',
    customRender: ({ text }) => {
      return render.renderDict(text, 'bom_production_purpose');
    },
    width: 100
  },
  {
    title: 'BOM类型',
    align: "center",
    dataIndex: 'bomType',
    customRender: ({ text }) => {
      return render.renderDict(text, 'bom_production_purpose');
    },
    width: 100
  },
  {
    title: 'BOM是否完整',
    align: "center",
    dataIndex: 'isComplete',
    customRender: ({ text }) => {
      return text == 1 ? '是' : text == 0 ? '否' : ''
    },
    width: 120
  },
  {
    title: '图号',
    align: "center",
    dataIndex: 'drawingNo',
    width: 140
  },
  {
    title: '批量',
    align: "center",
    dataIndex: 'batchNumber',
    width: 80
  },
  {
    title: '主批量',
    align: "center",
    dataIndex: 'masterBatch',
    customRender: ({ text }) => {
      return render.renderDict(text, 'bom_master_batch');
    },
    width: 100
  },
  {
    title: '发料方式',
    align: "center",
    dataIndex: 'issuanceMode',
    customRender: ({ text }) => {
      return render.renderDict(text, 'bom_issuance_mode');
    },
    width: 80
  },
  {
    title: '替代控制方式',
    align: "center",
    dataIndex: 'replaceControlMode',
    customRender: ({ text }) => {
      return text == 0 ? "全部替代" : text == 1 ? '部分替代' : ''
    },
    width: 100
  },
  {
    title: '供应方式',
    align: "center",
    dataIndex: 'supplyMode',
    customRender: ({ text }) => {
      return render.renderDict(text, 'bom_supply_mode');
    },
    width: 100
  },
  {
    title: '存储地点',
    align: "center",
    dataIndex: 'warehouseName',
    width: 100
  },
  {
    title: '齐套发料',
    align: "center",
    dataIndex: 'completeMaterial',
    customRender: ({ text }) => {
      return render.renderDict(text, 'bom_complete_material');
    },
    width: 100
  },
  {
    title: '备注',
    align: "center",
    dataIndex: 'remark',
    width: 180
  }
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "母件编号",
    field: "materialCode",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "母件名称",
    field: "materialName",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "单位",
    field: "unitName",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "版本",
    field: "bomVersion",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "项目",
    field: "projectCode",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "生效日期",
    field: "effectiveDate",
    component: 'DatePicker',
    colProps: { span: 6 }
  },
  {
    label: "失效日期",
    field: "expirationDate",
    component: 'DatePicker',
    colProps: { span: 6 },
  },
  {
    label: "BOM类型",
    field: "bomType",
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "bom_bom_type"
    },
    colProps: { span: 6 },
  },
  {
    label: "主批量",
    field: "masterBatch",
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "bom_master_batch"
    },
    colProps: { span: 6 },
  },
  {
    label: "发料方式",
    field: "issuanceMode",
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "bom_issuance_mode"
    },
    colProps: { span: 6 },
  },
  {
    label: "替代控制方式",
    field: "replaceControlMode",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "供应方式",
    field: "supplyMode",
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "bom_supply_mode"
    },
    colProps: { span: 6 },
  },
  {
    label: "齐套发料",
    field: "completeMaterial",
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "bom_complete_material"
    },
    colProps: { span: 6 },
  },
  {
    label: "单据状态",
    field: "billStatus",
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "bom_bill_status"
    },
    colProps: { span: 6 },
    ifShow:false
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '母件料品ID',
    field: 'materialId',
    component: 'Input',
    show: false,
  },
  // {
  //   label: '母件料品_料号',
  //   field: 'materialCode',
  //   component: 'Input',
  //   dynamicRules: ({ model, schema }) => {
  //     return [
  //       { required: true, message: '请输入母件料品_料号!' },
  //     ];
  //   },
  //   slot:'materialSlot'
  // },
  {
    label: '母件编号',
    field: 'materialCode',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择母件料号!' },
      ];
    },
    slot:'materialSlot'
  },
  {
    label: '单位ID',
    field: 'unitId',
    component: 'Input',
    show: false,
  },
  {
    label: '单位',
    field: 'unitName',
    component: 'Input',
    dynamicDisabled: ({ values }) => {
      return true;
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择单位!' },
      ];
    },
  },
{
  label: '生产部门编码',
  field: 'productDepartmentCode',
  component: 'Input',
  ifShow: false
},
{
  label: '生产部门',
  field: 'productDepartmentId',
  component: 'JSelectDept',
  componentProps: ({ }) => {
    return {
      multiple: false,
      showButton: false,
      checkable: false,
      isCode: true,
      rowKey: 'id',
      labelKey: 'departName'
    }
  },
  dynamicRules: () => {
    return [{
      required: true,
      message: '请选择生产部门!'
    },];
  },
},
  {
    label: '版本号',
    field: 'bomVersion',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入版本号!' },
      ];
    },
  },
  {
    label: '项目ID',
    field: 'projectId',
    component: 'Input',
    show: false,
  },
  {
    label: '项目',
    field: 'projectCode',
    component: 'Input',
  },
  {
    label: '生效日期',
    field: 'effectiveDate',
    component: 'DatePicker',
    defaultValue: newDate,
    componentProps: {
      valueFormat: 'YYYY-MM-DD'
    },
    dynamicRules: ({ model }) => rules.effectiveDate(model.expirationDate, true),
  },
  {
    label: '失效日期',
    field: 'expirationDate',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD'
    },
    dynamicRules: ({ model }) => rules.expirationDate(model.effectiveDate, true),
    defaultValue: '2099-12-31'
  },
  {
    label: 'BOM生产目的',
    field: 'productionPurpose',
    component: 'JDictSelectTag',
    defaultValue: 0,
    componentProps: {
      dictCode: "bom_production_purpose",
      stringToNumber: true,
    },
  },
  // 咨询过丁总，BOM生产目的和BOM类型筛选的是一样的数据
  {
    label: 'BOM类型',
    field: 'bomType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "bom_production_purpose",
      stringToNumber: true,
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择BOM类型!' },
      ];
    },
  },
  {
    label: '入库仓库Id',
    field:"warehouseId",
    component:"Input",
    show:false
  },
  {
    label: '入库仓库',
    field:"warehouseName",
    component:"Input",
    slot:'warehouse'
  },
  {
    label: '工程图号',
    field: 'drawingNo',
    component: 'Input',
  },
  {
    label: '批量',
    field: 'batchNumber',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入批量!' },
      ];
    },
  },
  {
    label: '主批量',
    field: 'masterBatch',
    component: 'JDictSelectTag',
    defaultValue: 0,
    componentProps: {
      dictCode: "bom_master_batch",
      stringToNumber: true,
    },
  },
  {
    label: '发料方式',
    field: 'issuanceMode',
    component: 'JDictSelectTag',
    defaultValue: 0,
    componentProps: {
      dictCode: "bom_issuance_mode",
      stringToNumber: true,
    },
    ifShow: false
  },
  {
    field: 'replaceControlMode',
    label: '替代控制方式',
    component: 'Select',
    componentProps: {
      options: [
        { label: '全部替代', value: 0 },
        { label: '部分替代', value: 1 },
      ],
    },
    ifShow: false
  },
  {
    label: '供应方式',
    field: 'supplyMode',
    component: 'JDictSelectTag',
    defaultValue: 0,
    componentProps: {
      dictCode: "bom_supply_mode",
      stringToNumber: true,
    },
    ifShow: false
  },
  {
    label: 'BOM是否完整',
    field: 'isComplete',
    component: 'Select',
    defaultValue: 1,
    componentProps: {
      options: [{
        value: 1, label: '是'
      },
      {
        value: 0, label: '否'
      }
      ],
      stringToNumber: true,
    },
  },
  {
    label: '供应组织ID',
    field: 'supplyOrganizationId',
    component: 'InputNumber',
    show: false
  },
  {
    label: '供应组织',
    field: 'supplyOrganizationName',
    component: 'Input',
    slot: 'organizationSlot',
  },
  {
    label: '指定厂牌',
    field: 'designatedBrand',
    defaultValue: 1,
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "bom_designated_brand",
      stringToNumber: true,
    },
    ifShow: false
  },
  {
    label: '厂牌',
    field: 'brand',
    component: 'Input',
    ifShow: false
  },
  {
    label: '计算成本',
    field: 'calculateCosts',
    defaultValue: 1,
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "bom_calculate_costs",
      stringToNumber: true,
    },
    ifShow: false
  },
  {
    label: '齐套发料',
    field: 'completeMaterial',
    component: 'JDictSelectTag',
    defaultValue: 0,
    componentProps: {
      dictCode: "bom_complete_material",
      stringToNumber: true,
    },
  },
  {
    label: '单据状态',
    field: 'billStatus',
    component: 'JDictSelectTag',
    defaultValue: 0,
    componentProps: {
      dictCode: "bom_bill_status",
      stringToNumber: true,
    },
    ifShow:false
  },
  {
    label: '备注',
    field: 'remark',
    component: 'Input',
  },
  {
    label: '第三方编码',
    field: 'thirdPartyCode',
    component: 'Input'
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];
//子表单数据
//子表表格配置
export const basMaterialBomChildColumns: JVxeColumn[] = [
  {
    title: '产品BOMID',
    key: 'materialBomId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '子件类型',
    key: 'childType',
    type: JVxeTypes.select,
    width: "120px",
    placeholder: '请选择${title}',
    defaultValue: 0,
    options: [{
      text: '标准',
      value: 0
    }],
    validateRules: [{ required: true, message: '${title}不能为空' }],
  },
  {
    title: '子件料品ID',
    key: 'materialId',
    type: JVxeTypes.hidden,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '子件料号',
    key: 'materialCode',
    type: JVxeTypes.slot,
    width: "160px",
    slotName: 'action',
    validateRules: [{ required: true, message: '${title}不能为空' }],
  },
  {
    title: '子件料品',
    key: 'materialName',
    type: JVxeTypes.normal,
    width: "160px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  // {
  //   title: '子级BOMid',
  //   key: 'childId',
  //   type: JVxeTypes.hidden,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  //   slotName: 'childSlot',
  // },
  // {
  //   title: '子级BOM',
  //   key: 'childName',
  //   type: JVxeTypes.slot,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  //   slotName: 'childSlot',
  // },

  {
    title: '单位ID',
    key: 'unitId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '单位',
    key: 'unitName',
    width: "80px",
    type: JVxeTypes.input,
    validateRules: [{ required: true, message: '${title}不能为空' }],
    disabled:true
  },
  {
    title: '发料仓库Id',
    key: 'warehouseId',
    width: "80px",
    type: JVxeTypes.hidden
  },
  {
    title: '发料仓库',
    key: 'warehouseName',
    width: "200px",
    type: JVxeTypes.normal
  },
  {
    title: '用量类型 ',
    key: 'consumptionType',
    type: JVxeTypes.select,
    width: "120px",
    placeholder: '请输入${title}',
    validateRules: [{ required: true, message: '${title}不能为空' }],
    defaultValue: 0,
    options: [{
      text: '变动',
      value: 0
    }]
  },
  {
    title: '用量',
    key: 'consumption',
    type: JVxeTypes.inputNumber,
    width: "100px",
    placeholder: '请输入${title}',
    validateRules: [{ required: true, message: '${title}不能为空' }],
    defaultValue: '',
    align: 'right'
  },
  {
    title: '母件底数',
    key: 'baseNumber',
    type: JVxeTypes.inputNumber,
    width: "140px",
    placeholder: '请输入${title}',
    validateRules: [{ required: true, message: '${title}不能为空' }],
    defaultValue: '',
    align: 'right'
  },
  {
    title: '虚拟',
    key: 'invented',
    type: JVxeTypes.select,
    width: "100px",
    placeholder: '请选择${title}',
    defaultValue: '',
    options: [{
      text: '否',
      value: 0
    },
    {
      text: '是',
      value: 1
    }
    ]
  },
  {
    title: '发料方式',
    key: 'issuanceMode',
    type: JVxeTypes.select,
    width: "120px",
    defaultValue: '0',
    dictCode: "bom_issuance_mode",
  },
  {
    title: '供应方式',
    key: 'supplyMode',
    type: JVxeTypes.select,
    width: "120px",
    defaultValue: '0',
    dictCode: "bom_supply_mode",
  },
  {
    title: '指定厂牌',
    key: 'designatedBrand',
    type: JVxeTypes.select,
    width: "120px",
    defaultValue: '1',
    dictCode: "bom_designated_brand",
  },  
  {
    title: '厂牌',
    key: 'brand',
    type: JVxeTypes.input,
    width: "120px",
    placeholder: '请输入${title}'
  },
  {
    title: '计算成本',
    key: 'calculateCosts',
    type: JVxeTypes.select,
    width: "120px",
    defaultValue: '1',
    dictCode: "bom_calculate_costs",
  },  
  {
    title: '固定损耗',
    key: 'fixedLoss',
    type: JVxeTypes.inputNumber,
    width: "120px",
    placeholder: '请输入${title}',
    align: 'right'
  }, {
    title: '变动损耗',
    key: 'variableLoss',
    type: JVxeTypes.inputNumber,
    formatter({cellValue, row, column}){
      if(cellValue) return cellValue+'%';
    },
    width: "120px",
    placeholder: '请输入${title}',
    align: 'right'
  },
  {
    title: '工序号',
    key: 'operationNo',
    type: JVxeTypes.input,
    width: "120px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '替代控制方式',
    key: 'replaceControlMode',
    type: JVxeTypes.select,
    width: "140px",
    placeholder: '请输入${title}',
    validateRules: [{ required: true, message: '${title}不能为空' }],
    defaultValue: '',
    options: [{
      text: '全部替代',
      value: 0
    },
    {
      text: '部分替代',
      value: 1
    }
    ]
  },
  {
    title: '生效日期',
    key: 'effectiveDate',
    type: JVxeTypes.date,
    width: "120px",
    placeholder: '请输入${title}',
    validateRules: [{ required: true, message: '${title}不能为空' }],
    defaultValue: newDate,
  },
  {
    title: '失效日期',
    key: 'expirationDate',
    type: JVxeTypes.date,
    width: "120px",
    placeholder: '请输入${title}',
    validateRules: [{ required: true, message: '${title}不能为空' }],
    defaultValue: '2099-12-31',
  },
  {
    title: '第三方编码',
    key: 'thirdPartyCode',
    type: JVxeTypes.input,
    width: "140px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
]
export const basMaterialBomTechnologyColumns: JVxeColumn[] = [
  {
    title: '产品BOMID',
    key: 'materialBomId',
    type: JVxeTypes.hidden,
  },
  {
    title: '工序号',
    key: 'processManagementCode',
    type: JVxeTypes.input,
    width: "150px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '工序id',
    key: 'processManagementId',
    type: JVxeTypes.hidden,
    width: "120px",
  },
  {
    title: '工序',
    key: 'processManagementName',
    type: JVxeTypes.slot,
    width: "180px",
    placeholder: '请输入${title}',
    defaultValue: '',
    slotName:'operationSlot'
  },
  {
    title: '工种',
    key: 'workType',
    type: JVxeTypes.input,
    width: "120px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '图号',
    key: 'drawingNo',
    type: JVxeTypes.input,
    width: "140px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '是否委外工序',
    key: 'subcontractingOperation',
    type: JVxeTypes.select,
    width: "160px",
    placeholder: '请输入${title}',
    defaultValue: '',
    options: [{
      text: '否',
      value: 0
    },
    {
      text: '是',
      value: 1
    }
    ]
  },
  {
    title: '第三方编码',
    key: 'thirdPartyCode',
    type: JVxeTypes.input,
    width: "140px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
]
export const basMaterialBomReplaceColumns: JVxeColumn[] = [
  {
    title: '产品BOMID',
    key: 'materialBomId',
    type: JVxeTypes.hidden,
  },
  {
    title: '替代顺序',
    key: 'alternateOrder',
    type: JVxeTypes.inputNumber,
    width: "160px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '主料',
    key: 'masterMaterial',
    type: JVxeTypes.select,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
    options: [{
      text: '否',
      value: 0
    },
    {
      text: '是',
      value: 1
    }
    ]
  },
  // {
  //   title: '替代料品ID',
  //   key: 'materialId',
  //   type: JVxeTypes.hidden,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  // {
  //   title: '替代料品编号',
  //   key: 'materialCode',
  //   type: JVxeTypes.input,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  {
    title: '替代料品',
    key: 'materialName',
    type: JVxeTypes.slot,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
    slotName: 'action',
  },
  {
    title: '用量',
    key: 'consumption',
    type: JVxeTypes.inputNumber,
    width: "80px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '母件底数',
    key: 'baseNumber',
    type: JVxeTypes.inputNumber,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '单位ID',
    key: 'unitId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '单位',
    key: 'unitName',
    width: "100px",
    type: JVxeTypes.input,
    disabled:true
  },
  {
    title: '第三方编码',
    key: 'thirdPartyCode',
    type: JVxeTypes.input,
    width: "140px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
]


/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}